//
//  AXFProductCell.m
//  aixinfeng005
//
//  Created by apple on 2016/10/11.
//  Copyright © 2016年 BBSWaitting. All rights reserved.
//

#import "AXFProductCell.h"
#import "UILabel+Addition.h"
#import "AXFSupermarketModel.h"
#import "AXFAddproductView.h"

@interface AXFProductCell ()
/**
 *  食品图片
 */
@property (weak, nonatomic)  UIImageView *iconView;
/**
 *  精选图标
 */
@property(nonatomic,weak)UIImageView * choiceView;
/**
 * 名称
 */
@property (weak, nonatomic)  UILabel *nameLabel;
/**
 *  详情列表
 */
@property (weak, nonatomic)  UILabel *detailLabel;
/**
 *  规格
 */
@property (weak, nonatomic)  UILabel *specificsLabel;
/**
 *  售价
 */
@property (weak, nonatomic)  UILabel *priceLabel;
/**
 *  原价
 */
@property (weak, nonatomic)  UILabel *market_priceLabel;



@end


@implementation AXFProductCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellAccessoryNone;
        
        [self setupUI];
        //MARK:- 定义block实现动画

        
    }
    return self;
}

#pragma mark -- 搭建界面
- (void)setupUI
{
   UIImageView *iconView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:iconView];
    
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(10);
        make.width.height.offset(80);
    }];
    
    UIImageView *choiceView = [[UIImageView alloc] init];
    [self.contentView addSubview:choiceView];
    [choiceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView);
        make.left.equalTo(iconView.mas_right).offset(5);
        make.width.offset(30);
        make.height.offset(15);
    }];
    
    UILabel *nameLabel = [UILabel makeLabelText:@"天天练" andTextColor:[UIColor blackColor] andTextFont:13];
    
    [self.contentView addSubview:nameLabel];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(iconView);
        make.left.equalTo(choiceView.mas_right).offset(5);

    }];
    UILabel *detailLabel = [UILabel makeLabelText:@"买一赠一" andTextColor:[UIColor whiteColor] andTextFont:12];
    detailLabel.backgroundColor = [UIColor redColor];
    detailLabel.layer.cornerRadius = 3;
    detailLabel.layer.masksToBounds = YES;
    [self.contentView addSubview:detailLabel];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(choiceView.mas_bottom).offset(3);
        make.left.equalTo(choiceView);
        
    }];
    
    UILabel *specificsLabel = [UILabel makeLabelText:@"400/盒" andTextColor:[UIColor blackColor] andTextFont:12];
    
    [self.contentView addSubview:specificsLabel];
    [specificsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detailLabel.mas_bottom).offset(3);
        make.left.equalTo(detailLabel);
        
    }];
    
    UILabel *priceLabel = [UILabel makeLabelText:@"￥40" andTextColor:[UIColor redColor] andTextFont:12];
    
   // priceLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:priceLabel];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(specificsLabel.mas_bottom).offset(3);
        make.left.equalTo(specificsLabel);
        
    }];
    
    UILabel *market_priceLabel = [UILabel makeLabelText:@"￥40" andTextColor:[UIColor lightGrayColor] andTextFont:12];
    
  // market_priceLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:market_priceLabel];
    [market_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(priceLabel);
        make.left.equalTo(priceLabel.mas_right).offset(10);
        
    }];
    
    void(^animationBLock)(CGPoint point) = ^(CGPoint point)
    {
        self.willAnimation(point);
        
    };
    
  
    
    AXFAddproductView *addView = [AXFAddproductView makeView];
    
    addView.cellBlock = animationBLock;
    
    [self.contentView addSubview:addView];
    
    [addView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(87, 27));
        make.bottom.equalTo(priceLabel);
        make.right.equalTo(self.contentView.mas_right);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self);
        // 下面这个commentBtn 在别的项目换成当前cell最顶部的控件即可
        make.bottom.equalTo(priceLabel.mas_bottom).offset(10);
        make.width.equalTo(self.mas_width);
    }];
    
    
    
    
    self.iconView = iconView;
    self.detailLabel = detailLabel;
    self.priceLabel = priceLabel;
    self.market_priceLabel = market_priceLabel;
    self.specificsLabel = specificsLabel;
    self.choiceView = choiceView;
    self.nameLabel = nameLabel;

    
}




-(void)setData:(AXFSupermarketModel *)data
{
    _data = data;
    
    self.nameLabel.text = data.name;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString: data.img]];
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@",data.price];
    self.market_priceLabel.text = [NSString stringWithFormat:@"￥%@",data.market_price];
    
    self.specificsLabel.text = data.specifics;
   // NSLog(@"%@",data.pm_desc);
    if (data.pm_desc.length > 0) {
        self.detailLabel.hidden = NO;
        self.detailLabel.text = data.pm_desc;
    }else
    {
        self.detailLabel.hidden = YES;
    }
    
}


@end
